import React, { useState } from 'react';
import { IFormItem, Itype } from '@/base-ui/form';
import http from '@/services/request';
import { Space, Button, Select } from 'antd';
import { Input } from 'antd';
import { RightOutlined, UpOutlined } from '@ant-design/icons';

const { Option } = Select;

const { Search } = Input;

/* 搜索区域 */

export const PageSearchConfig: IFormItem[] = [
  {
    type: 'input' as Itype,
    label: '订单编号',
    name: 'id',
    placeholder: '请输入订单编号'
  },
  {
    type: 'input' as Itype,
    label: '批次编号',
    name: 'batchId',
    placeholder: '请输入批次编号'
  },
  {
    type: 'input' as Itype,
    label: '分发批次编号',
    name: 'distributionBatchId',
    placeholder: '请输入分发批次编号'
  },
  {
    type: 'input' as Itype,
    label: '批次等级',
    name: 'batchGrade',
    placeholder: '请输入批次等级'
  },
  {
    type: 'input' as Itype,
    label: '批次品种',
    name: 'batchVariety',
    placeholder: '请输入批次品种'
  },
  {
    type: 'input' as Itype,
    label: '回购单价',
    name: 'buybackPrice',
    placeholder: '请输入回购单价'
  },
  {
    type: 'input' as Itype,
    label: '回购数量',
    name: 'buybackQuantity',
    placeholder: '请输入回购数量'
  },
  // {
  //   type: 'datepicker' as Itype,
  //   label: '回购时间',
  //   name: 'buybackTime',
  //   placeholder: ''
  // },
  {
    type: 'input' as Itype,
    label: '总金额',
    name: 'totalPrice',
    placeholder: '请输入总金额'
  },
  {
    type: 'input' as Itype,
    label: '负责人电话',
    name: 'responsiblePhone',
    placeholder: '请输入负责人电话号码'
  },
  {
    type: 'input' as Itype,
    label: '负责人名',
    name: 'responsibleName',
    placeholder: '请输入负责人名'
  },
  {
    type: 'input' as Itype,
    label: '疫苗接种',
    name: 'vaccinationStatus',
    placeholder: '请输入疫苗接种状态'
  },
  {
    type: 'input' as Itype,
    label: '肉鸡日龄',
    name: 'dayAge',
    placeholder: '请输入肉鸡日龄'
  },
  {
    type: 'input' as Itype,
    label: '合作社编号',
    name: 'daycoopId',
    placeholder: '请输入合作社编号'
  },
  {
    type: 'input' as Itype,
    label: '合作社名称',
    name: 'coopName',
    placeholder: '请输入合作社名称'
  },
  {
    type: 'input' as Itype,
    label: '备注',
    name: 'remark',
    placeholder: '请输入备注'
  }
];

//高级检索
export const UseSearch = (props: any) => {
  return (
    <Space style={{ float: 'right' }}>
      {props.isMoreSearchShow ? (
        <Button
          type="link"
          size="large"
          onClick={() => {
            props.setisMoreSearchShow(false);
            props.setsearchMore(false);
          }}
        >
          收起
          <UpOutlined />
        </Button>
      ) : (
        <>
          <Button
            type="link"
            size="middle"
            onClick={() => {
              props.setisMoreSearchShow(true);props.setsearchMore(true);
            }}
          >
            高级检索
            <RightOutlined style={{ marginLeft: '1px' }} />
          </Button>
        </>
      )}
    </Space>
  );
};

export const SearchSelector = (props: any) => {
  const [searchid, setsearchid]: any = useState('coopId');
  return (
    <div
      style={{
        display: 'inline-block',
        width: '380px',
        marginBottom: 10,
        marginRight: 10,
        float: 'right'
      }}
    >
      <Select
        defaultValue={Options[0].label}
        style={{ width: 100 }}
        defaultActiveFirstOption
        onSelect={(value: string, option: any) => {
          setsearchid(option.key);
        }}
      >
        {Options.map((i) => (
          <Option value={i.label} key={i.value} children={null} />
        ))}
      </Select>
      <Search
        placeholder="请输入您要查的数据"
        onSearch={(e) => {
          if (e === '') {
            http.get('/feed/chickenBuybackFarming/list/1/10').then((res) => {
              props.dataSource(res.data.records);
            });
            return;
          }
          switch (searchid) {
            case 'id': {
              http(`/feed/chickenBuybackFarming/get/${e}`).then((res) => {
                const arr: any = [];
                arr.push(res.data);
                props.dataSource(arr);
              });
              break;
            }
            case 'coopId': {
              http(`/feed/chickenBuybackFarming/get/coopId/${e}`).then(
                (res) => {
                  props.dataSource(res.data);
                }
              );
              break;
            }
            case 'responsibledId': {
              http(`/feed/chickenBuybackFarming/get/responsibleId/${e}`).then(
                (res) => {
                  props.dataSource(res.data);
                }
              );
              break;
            }

            default: {
              break;
            }
          }
        }}
        style={{ width: '280px' }}
        enterButton
      />
    </div>
  );
};
export const Searchdow = () => {
  return;
};

const Options = [
  { label: '合作社ID', value: 'coopId', onClick: (e: any) => {} },
  { label: '养殖负责人ID', value: 'responsibledId', onClick: (e: any) => {} },
  { label: 'ID', value: 'id', onClick: (e: any) => {} }
];

/* 表格区域 */

//复选框的接口
export interface DataType {
  id: number;
  key: React.Key;
  name: string;
  age: number;
  address: string;
}
